package Calculation;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Hua YY
 * Date: 2024-10-05
 * Time: 20:55
 */
public class Test3 {
    //快乐数
    class Solution {
        public  int sumResult(int n){
            int sum = 0;
            while(n != 0){
                //int tem = n % 10;
                //sum += tem * tem;
                sum += Math.pow(n%10,2);
                n = n/10;
            }
            return sum;
        }
        public boolean isHappy(int n) {
            int slow = n ,fast = sumResult(n);
            while(slow != fast){
                slow = sumResult(slow);
                fast = sumResult(sumResult(fast));
            }
            return slow == 1;
        }
    }
}
